package org.example.back.task;

import org.example.back.service.advice.UserSleepAdviceService;
import org.example.back.service.advice.UserSportAdviceService;
import org.example.back.service.advice.UserMealAdviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class AdviceCacheCleaner {

    @Autowired
    private UserSleepAdviceService userSleepAdviceService;

    @Autowired
    private UserSportAdviceService userSportAdviceService;

    @Autowired
    private UserMealAdviceService userMealAdviceService;

    // 每天凌晨2点，清理所有“日”睡眠建议缓存
    @Scheduled(cron = "0 0 2 * * ?")
    public void cleanDailySleepAdviceCache() {
        userSleepAdviceService.cleanDailyAdviceCache();
        userSportAdviceService.cleanDailyAdviceCache();
        userMealAdviceService.cleanDailyAdviceCache();
        System.out.println("已清理所有日建议缓存");
    }

}
